package com.aijk.web.admin.controller.medical;

import com.aijk.commons.exception.ErrorCodeException;
import com.aijk.commons.mijo.utils.PojoUtil;
import com.aijk.commons.utils.Utils;
import com.aijk.medical.api.FdSignListApi;
import com.aijk.medical.api.MedRecordApi;
import com.aijk.medical.api.MedResidentApi;
import com.aijk.medical.api.SpckRecordApi;
import com.aijk.medical.model.FdSignListQo;
import com.aijk.medical.model.MedRecord;
import com.aijk.medical.model.MedResident;
import com.aijk.medical.model.vo.FdSignListVo;
import com.aijk.web.admin.RetMsg;
import com.aijk.web.admin.controller.BaseController;
import com.aijk.web.admin.entity.Constant;
import com.aijk.web.admin.entity.KeyValues;
import com.aijk.web.admin.model.SpckItemResidentExt;
import com.aijk.web.admin.utils.DataTableUtil;
import com.aijk.web.admin.utils.ExcelUtils;
import com.github.pagehelper.PageInfo;
import com.google.gson.Gson;
import com.lifesea.familydoctor.api.FdServantApi;
import com.lifesea.familydoctor.api.FdTeamApi;
import com.lifesea.familydoctor.api.FdTeamMemberApi;
import com.lifesea.familydoctor.model.FdServant;
import com.lifesea.familydoctor.model.FdTeam;
import com.lifesea.familydoctor.model.qo.FdTeamMemberQo;
import com.lifesea.familydoctor.model.vo.FdSignDealVo;
import com.lifesea.familydoctor.model.vo.FdTeamMemberVo;
import com.lifesea.model.SpckItem;
import com.lifesea.model.SpckItemResident;
import com.lifesea.model.SpckPackage;
import com.lifesea.model.SpckPackageResident;
import com.lifesea.model.vo.SpckItemVo;
import com.lifesea.model.vo.SpckPackageListVo;
import com.lifesea.model.vo.SpckPackageVo;
import com.lifesea.spck.facade.SpckItemFacade;
import com.lifesea.spck.facade.SpckItemResidentFacade;
import com.lifesea.spck.facade.SpckPackageFacade;
import com.lifesea.spck.facade.SpckPackageResidentFacade;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import java.io.File;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping("/medical/sign")
public class FdSignListController  extends BaseController {

    @Autowired
    private FdSignListApi signListApi;

    @Autowired
    private SpckPackageResidentFacade spckPackageResidentFacade;

    @Autowired
    private SpckItemResidentFacade spckItemResidentFacade;

    @Autowired
    private SpckRecordApi spckRecordApi;

    @Autowired
    private MedRecordApi medRecordApi;

    @Autowired
    private SpckPackageFacade spckPackageFacade;

    @Autowired
    private SpckItemFacade spckItemFacade;

    @Autowired
    private FdTeamMemberApi fdTeamMemberApi;

    @Autowired
    private MedResidentApi medResidentApi;

    @Autowired
    private FdTeamApi fdTeamApi;

    @Autowired
    private FdServantApi fdServantApi;



    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public String list_view(Model model) {
        //默认获取当前团队服务记录
        HttpSession session = request.getSession();
        FdTeam teamInfo = (FdTeam) session.getAttribute(Constant.SESSION_TEAM);
        if (teamInfo != null) {
            model.addAttribute("teamId", teamInfo.getTeamId());
            model.addAttribute("teamName", teamInfo.getTeamName());
        }else{
            model.addAttribute("msg", "身份信息已失效，请重新登录！");
            return "/error/error_msg";
        }
        model.addAttribute("idcard",(String) session.getAttribute(Constant.SESSION_IDCARD));
        return "medical/sign/sign_list";
    }

    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public RetMsg list(@RequestParam HashMap skey, @RequestParam(value = "draw", defaultValue = "1") Integer draw) {
        Long iTotalRecords;
        DataTableUtil.FormatOptions(skey);
        FdSignListQo qo = DataTableUtil.fillQo(skey,FdSignListQo.class);
        draw += 1;

        RetMsg regMsg = new RetMsg();
        HttpSession session = request.getSession();
        FdTeam teamInfo = (FdTeam) session.getAttribute(Constant.SESSION_TEAM);
        if (teamInfo != null) {
            List<Long> ecn =  signListApi.getSignEcn(teamInfo.getTeamId() , Utils.toInteger(skey.get("signStatus")));
            if(ecn==null || ecn.size() == 0){
                regMsg.put("data", new ArrayList<String>());
                regMsg.put("draw", draw);
                regMsg.put("recordsTotal", 0);
                regMsg.put("recordsFiltered", 0);
                return regMsg;
            }
            qo.setEcnList(ecn);
            qo.setIsTimeDesc("1");
            PageInfo<FdSignListVo> pageInfo = signListApi.page(qo);
            iTotalRecords =pageInfo.getTotal();


            if(skey.containsKey("signStatus") && skey.get("signStatus").equals("12")){
                if(pageInfo.getList()!=null){
                    for (FdSignListVo vo : pageInfo.getList()){
                        vo.setMemoResident(vo.getMemo()==null?"":vo.getMemo());
                    }
                }
            }

            if(skey.containsKey("signStatus") && skey.get("signStatus").equals("10")){
                if(pageInfo.getList()!=null){
                    for (FdSignListVo vo : pageInfo.getList()){
                        vo.setMemoResident(vo.getMemoDoctor()==null?"":vo.getMemoDoctor());
                    }
                }
            }

//            if(skey.containsKey("signStatus") && (skey.get("signStatus").equals("11")||skey.get("signStatus").equals("31"))){
//                if(pageInfo.getList()!=null){
//                    for (FdSignListVo vo : pageInfo.getList()){
//                        vo.setMemoResident(vo.getMemo());
//                    }
//                }
//            }

            regMsg.put("data", pageInfo.getList());
            regMsg.put("draw", draw);
            regMsg.put("recordsTotal", iTotalRecords);
            regMsg.put("recordsFiltered", iTotalRecords);
        }else{
            regMsg.put("data", new ArrayList<String>());
            regMsg.put("draw", draw);
            regMsg.put("recordsTotal", 0);
            regMsg.put("recordsFiltered", 0);
        }
        return regMsg;
    }

    @RequestMapping(value = "/edit", method = RequestMethod.GET)
    public String add_view(Model model , Integer id) {
        //是否只展示详情
        String infoOnly = request.getParameter("infoOnly");
        if(StringUtils.isNotBlank(infoOnly)){
            model.addAttribute("infoOnly",infoOnly);
        }
        FdSignListVo fdSignListVo = signListApi.find(id);

        List<KeyValues> keyValuesList = Constant.getPersonCategory();
        LinkedHashMap<String,String> mMap=new LinkedHashMap<>();

        String types = signListApi.getMedResidentType(fdSignListVo.getEcn());
        if(types!=null && !types.equals("")){
            String[] as = types.split(",");
            for (String str : as){
                for (KeyValues kv : keyValuesList){
                    if(str.equals(kv.getKey())){
                        kv.setIscheck(1);
                    }
                }
            }
        }
        if(fdSignListVo.getSex().equals("M")){
            fdSignListVo.setSex("男");
        }else{
            fdSignListVo.setSex("女");
        }

        model.addAttribute("kv",keyValuesList);
        model.addAttribute("kvjson",new Gson().toJson(keyValuesList));
        model.addAttribute("data",fdSignListVo);
        model.addAttribute("isshow" , fdSignListVo.getSignStatus());
        model.addAttribute("ecn",fdSignListVo.getEcn());
        model.addAttribute("method","edit");
        return "medical/sign/sign_edit";
    }

    @RequestMapping(value = "/add/type", method = RequestMethod.POST)
    @ResponseBody
    @Transactional
    public RetMsg add_type(Integer signId , String type, String memo) {
        RetMsg msg = new RetMsg();
        try {
            FdSignListVo vo = signListApi.find(signId);
            signListApi.saveMedResidentType( vo.getEcn() ,  vo.getUid() ,  vo.getTeamId() ,  type);
            vo.setSignId(signId);
            vo.setMemoResident(memo);
            signListApi.update(vo);
            msg.put("code",0);
        }catch (ErrorCodeException e){
            e.printStackTrace();
            msg.put("code",-1);
        }
        return msg;
    }

    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    @ResponseBody
    @Transactional
    public RetMsg add(@Valid FdSignListVo data) {
        RetMsg msg = new RetMsg();
        try {
            signListApi.update(data);
            msg.put("code",0);
        }catch (ErrorCodeException e){
            e.printStackTrace();
            msg.put("code",-1);
        }
        return msg;
    }

    @RequestMapping(value = "/record/add", method = RequestMethod.POST)
    @ResponseBody
    @Transactional
    public RetMsg addrecord(MedRecord data,Integer sirid,String signId,String image1,String image2,String image3,String image4,String image5,String image6) {
        RetMsg msg = new RetMsg();
        try {
            MedResident medResident = medResidentApi.findOne(data.getEcn());
            FdServant fdServant = fdServantApi.find(data.getServantId());
            FdSignListVo sign = signListApi.find(Integer.valueOf(signId));

            if (fdServant==null){
                return msg.failed("服务者信息不存在");
            }
            if (sign!= null){
                if (sign.getSignStatus()!=11&&sign.getSignStatus()!=20){
                    return msg.failed("用户签约状态错误");
                }
            }
            data.setEavatar(medResident.getAvatar());
            data.setIdcard(medResident.getIdcard());
            data.setCreateTime(new Date());
            data.setServantMobile(fdServant.getMobile());
            data.setServantName(fdServant.getName());

            //图片处理image
            String image = "";
            if (StringUtils.isNotEmpty(image1)){
                image = image1;
                if (StringUtils.isNotEmpty(image2)){
                    image += ","+image2;
                }if (StringUtils.isNotEmpty(image3)){
                    image += ","+image3;
                }if (StringUtils.isNotEmpty(image4)){
                    image += ","+image4;
                }if (StringUtils.isNotEmpty(image5)){
                    image += ","+image5;
                }if (StringUtils.isNotEmpty(image6)){
                    image += ","+image6;
                }
            }
            data.setImage(image);


            /**服务限次,服务次数减少 使用次数增加**/
            SpckItemResident spckItemResident = spckItemResidentFacade.get(sirid);
            if (spckItemResident != null) {
                if (spckItemResident.getResidueDegree() == 0){
                    return msg.failed("剩余次数不足");
                }
                if (spckItemResident.getResidueDegree() != null && spckItemResident.getResidueDegree() != 9999 && spckItemResident.getResidueDegree() > 0) {
                    spckItemResident.setResidueDegree(spckItemResident.getResidueDegree() - 1);
                }
                if (spckItemResident.getNoUse() != null) {
                    spckItemResident.setNoUse(spckItemResident.getNoUse() + 1);
                } else {
                    spckItemResident.setNoUse(1);
                }
                spckItemResidentFacade.updateByPrimary(spckItemResident);
            }
            medRecordApi.save(data);
            return msg.success();
        }catch (ErrorCodeException e){
            e.printStackTrace();
            return msg.failed();
        }

    }

    @RequestMapping(value = "/deal/edit", method = RequestMethod.GET)
    public String deal_edit(Model model , Integer id) {
        FdSignDealVo fdSignDealVo = signListApi.getSignDeal(id);
        FdSignListVo vo = signListApi.find(id);
        model.addAttribute("signId" , id);
        model.addAttribute("ecn" , vo.getEcn());
        model.addAttribute("data",fdSignDealVo);
        model.addAttribute("method","edit");
        return "medical/sign/deal_edit";
    }

    @RequestMapping(value = "/spck/list", method = RequestMethod.GET)
    public String list_view_spck(Model model , Integer id) {
        FdSignListVo fdSignListVo = signListApi.find(id);
        Integer status = Utils.toInteger(fdSignListVo.getSignStatus());
        SpckPackageListVo spckPackageListVo = signListApi.getResidentSpckList(fdSignListVo.getEcn());

        List<SpckPackageVo> list = new ArrayList<>();
        if(fdSignListVo!=null){
            if(spckPackageListVo.getBasicList()!=null && spckPackageListVo.getBasicList().size() > 0){
                for (SpckPackageVo vo : spckPackageListVo.getBasicList()){
//                    Integer status = Utils.toInteger(vo.getSignStatus());
                    if(vo.getSignStatus()!=null && status.equals(11)){
                        if(vo.getDefaultPrice()==null){
                            vo.setDefaultPrice(new BigDecimal(0));
                        }
                        list.add(vo);
                    }else if (vo.getSignStatus()!=null && status.equals(31)){
                        if(vo.getDefaultPrice()==null){
                            vo.setDefaultPrice(new BigDecimal(0));
                        }
                        list.add(vo);
                    }
                }
            }

            if(spckPackageListVo.getIncrementList()!=null && spckPackageListVo.getIncrementList().size() > 0){
                for (SpckPackageVo vo : spckPackageListVo.getIncrementList()){
                    if(vo.getSignStatus()!=null && status.equals(11)){
                        if(vo.getDefaultPrice()==null){
                            vo.setDefaultPrice(new BigDecimal(0));
                        }
                        list.add(vo);
                    }else if (vo.getSignStatus()!=null && status.equals(31)){
                        if(vo.getDefaultPrice()==null){
                            vo.setDefaultPrice(new BigDecimal(0));
                        }
                        list.add(vo);
                    }
                }
            }
        }

        //默认获取当前团队服务记录
        HttpSession session = request.getSession();
        FdTeam teamInfo = (FdTeam) session.getAttribute(Constant.SESSION_TEAM);
        if (teamInfo != null) {
            model.addAttribute("teamId", teamInfo.getTeamId());
        }else{
            model.addAttribute("msg", "身份信息已失效，请重新登录！");
            return "/error/error_msg";
        }
        System.out.println("长度是："+list.size());
        model.addAttribute("isshow" , fdSignListVo.getSignStatus());
        model.addAttribute("data",new Gson().toJson(list));
        model.addAttribute("signId",id);
        model.addAttribute("ecn",fdSignListVo.getEcn());
        return "medical/sign/spck_list_edit";
    }

    @RequestMapping(value = "/spck/team/list", method = RequestMethod.GET)
    public String list_spck(Model model , Integer teamId , Integer signId , Long ecn) {
        SpckPackageListVo fdSignListVo = signListApi.getSpckList(teamId);

        List<SpckPackageVo> list = new ArrayList<>();
        //List<FdSignPackageExt> list1 = new ArrayList<>();
        if(fdSignListVo!=null){
            if(fdSignListVo.getBasicList()!=null && fdSignListVo.getBasicList().size() > 0){
                for (SpckPackageVo vo : fdSignListVo.getBasicList()){
                    if(vo.getPrice()==null){
                        vo.setPrice(new BigDecimal(0));
                    }
                    list.add(vo);
                }
            }

            if(fdSignListVo.getIncrementList()!=null && fdSignListVo.getIncrementList().size() > 0){
                for (SpckPackageVo vo : fdSignListVo.getIncrementList()){
                    if(vo.getPrice()==null){
                        vo.setPrice(new BigDecimal(0));
                    }
                    list.add(vo);
                }
            }
        }
        /*list1 = PojoUtil.convert(list, FdSignPackageExt.class);
        for (FdSignPackageExt fdSignPackageExt : list1){
            HashMap map = new HashMap();
            map.put("ecn",ecn);
            map.put("spckId",fdSignPackageExt.getId());
            map.put("status",11);
            List <SpckPackageResident> packageResidents = spckPackageResidentFacade.getList((Map)map);
            if (packageResidents.size()>0){
                fdSignPackageExt.setHasChosen(true);
            }else {
                fdSignPackageExt.setHasChosen(false);
            }
        }*/

        model.addAttribute("data",new Gson().toJson(list));
        model.addAttribute("teamId",teamId);
        model.addAttribute("signId",signId);
        model.addAttribute("ecn",ecn);
        return "medical/sign/spck_list_select_edit";
    }


    @RequestMapping(value = "/spck/add", method = RequestMethod.POST)
    @ResponseBody
    @Transactional
    public RetMsg add_spck(Long ecn , Integer teamId , Integer packageIdList , Integer signId) {
        RetMsg msg = new RetMsg();
        try {
            Integer prid = signListApi.saveSpckPackage(ecn, teamId, packageIdList, signId);

            SpckPackageListVo fdSignListVo = signListApi.getSpckList(teamId);
            List<SpckPackageVo> list = new ArrayList<>();
            if(fdSignListVo!=null){
                if(fdSignListVo.getBasicList()!=null && fdSignListVo.getBasicList().size() > 0){
                    for (SpckPackageVo vo : fdSignListVo.getBasicList()){
                        if(vo.getPrice()==null){
                            vo.setPrice(new BigDecimal(0));
                        }
                        list.add(vo);
                    }
                }

                if(fdSignListVo.getIncrementList()!=null && fdSignListVo.getIncrementList().size() > 0){
                    for (SpckPackageVo vo : fdSignListVo.getIncrementList()){
                        if(vo.getPrice()==null){
                            vo.setPrice(new BigDecimal(0));
                        }
                        list.add(vo);
                    }
                }
            }
            for (SpckPackageVo vo : list){
                if(vo.getId().equals(packageIdList) ){
                    msg.put("data",vo);
                }
            }

            msg.put("time" , new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
            msg.put("code",0);
            msg.put("prid",prid);
        }catch (ErrorCodeException e){
            e.printStackTrace();
            msg.put("code",-1);
        }
        return msg;
    }

//验证是否重复添加
    @RequestMapping(value = "/spck/readd", method = RequestMethod.POST)
    @ResponseBody
    @Transactional
    public RetMsg readd_spck(Long ecn , Integer teamId , Integer packageIdList , Integer signId) {
        RetMsg msg = new RetMsg();
        try {
            HashMap map = new HashMap();
            map.put("ecn",ecn);
            map.put("spckId",packageIdList);
            map.put("status",11);
            List <SpckPackageResident> packageResidents = spckPackageResidentFacade.getList((Map)map);
            if (packageResidents.size()>0){
                msg.put("code",0);
            }else {
                msg.put("code",1);
            }
        }catch (ErrorCodeException e){
            e.printStackTrace();
            msg.put("code",-1);
        }
        return msg;
    }


    @RequestMapping(value = "/spck/item/list", method = RequestMethod.GET)
    public String list_view_item_spck(Model model ,Integer teamIds,Integer spckId , Long ecn) {
        List<SpckItemVo> list = signListApi.getSpckItemList( spckId );
        if(list == null){
            list = new ArrayList<>();
        }
        model.addAttribute("data",new Gson().toJson(list));
        model.addAttribute("spckId",spckId);
        model.addAttribute("teamIds",teamIds);
        model.addAttribute("ecn",ecn);
        return "medical/sign/spck_list_edit_item";
    }

    @RequestMapping(value = "/spck/item/lists", method = RequestMethod.GET)
    public String list_view_item_spcks(Model model ,Integer teamIds,Integer spckId , Long ecn,Integer prid,String signId) {
        HashMap map = new HashMap();
        map.put("ecn",ecn);
        map.put("pckId",spckId);
        map.put("status",11);
        if (prid>0){
            map.put("prid",prid);
        }
        List<SpckItemResident> list = spckItemResidentFacade.getList(map);
        List<SpckItemResidentExt> list1 = PojoUtil.convert(list, SpckItemResidentExt.class);
        for (SpckItemResidentExt spckItemResidentExt:list1){
            if (spckItemResidentExt.getFrequency()==9999){
                spckItemResidentExt.setSycs("不限次");
            }else {
                spckItemResidentExt.setSycs(spckItemResidentExt.getResidueDegree()+"/"+spckItemResidentExt.getFrequency());
            }
        }
        SpckPackage spckPackage = spckPackageFacade.get(spckId);

        model.addAttribute("data",new Gson().toJson(list1));
        model.addAttribute("spckId",spckId);
        model.addAttribute("spck",spckPackage.getTitle());
        model.addAttribute("teamId",teamIds);
        model.addAttribute("ecn",ecn);
        model.addAttribute("prid",prid);
        model.addAttribute("signId",signId);
        return "medical/sign/spck_list_record_item";
    }

    @RequestMapping(value = "/spck/record/edit", method = RequestMethod.GET)
    public String list_view_item_record(Model model ,Integer teamId,Integer spckId , Long ecn,String prid,Integer srid,String spck,String signId) {
        SpckItemResident spckItemResident = spckItemResidentFacade.get(srid);
        SpckItem spckItem = spckItemFacade.get(spckItemResident.getItemId());
        SpckPackage spckPackage = spckPackageFacade.get(spckId);
        FdTeamMemberQo fdTeamMemberQo = new FdTeamMemberQo();
        fdTeamMemberQo.setTeamId(teamId);
        List<FdTeamMemberVo> fdTeamMembers = fdTeamMemberApi.list(fdTeamMemberQo);
        MedResident medResident = medResidentApi.findOne(ecn);
        FdTeam fdTeam = fdTeamApi.find(teamId);

        model.addAttribute("members",fdTeamMembers);
        model.addAttribute("itemId",spckItem.getId());
        model.addAttribute("item",spckItem);
        model.addAttribute("spckId",spckId);
        model.addAttribute("spck",spckPackage);
        model.addAttribute("teamId",teamId);
        model.addAttribute("team",fdTeam);
        model.addAttribute("ecn",ecn);
        model.addAttribute("srid",srid);
        model.addAttribute("medResident",medResident);
        model.addAttribute("prid",prid);
        model.addAttribute("signId",signId);
        return "medical/sign/edit_record";
    }

    @RequestMapping(value = "/adorup", method = RequestMethod.POST)
    @ResponseBody
    @Transactional
    public RetMsg add_sign(Integer signId ,Integer status , String memo) {
        RetMsg msg = new RetMsg();
        try {
            signListApi.signConsentOrCancel(signId , status);
            if(status == 12){
                FdSignListVo vo = new FdSignListVo();
                vo.setSignId(signId);
                if(!memo.equals("-1")){
                    vo.setMemo(memo);
                }
                signListApi.update(vo);
            }
            msg.put("code",0);
        }catch (ErrorCodeException e){
            e.printStackTrace();
            msg.put("code",-1);
        }
        return msg;
    }

    @RequestMapping(value = "/excel/create", method = RequestMethod.POST)
    @ResponseBody
    public RetMsg excelCreate(int signStatus , String username , String mobile) {
        RetMsg retMsg = new RetMsg();
        try {
            String fileName = "签约名单.xls"; //模板名称
            String pathurl = request.getServletContext().getRealPath("")+"download/";
            String[] handers = {"姓名","身份证","手机号","街道" , "团队名称" , "签约开始时间","签约结束时间"}; //列标题

            FdSignListQo qo = new FdSignListQo();
            qo.setSignStatus((byte)signStatus);
            HttpSession session = request.getSession();
            FdTeam teamInfo = (FdTeam) session.getAttribute(Constant.SESSION_TEAM);
            if (teamInfo != null) {
                qo.setTeamId(teamInfo.getTeamId());
            }else{
                retMsg.put("code" , -1);
                return retMsg;
            }

            List<Long> ecn =  signListApi.getSignEcn(teamInfo.getTeamId() , signStatus);
            if(ecn==null || ecn.size() == 0){
                retMsg.put("code" , -1);
                return retMsg;
            }
            qo.setEcnList(ecn);


            if(null!=username && !username.equals("-1"))
                qo.setUsername(username);
            if(null!=mobile && !mobile.equals("-1"))
                qo.setMobile(mobile);

            List<FdSignListVo> fdSignList = signListApi.getList(qo);
            if(fdSignList != null && fdSignList.size() > 0){
                File files = ExcelUtils.outputExcelTemplateStatistics(pathurl+fileName ,handers,null , null , fdSignList );
                retMsg.put("path" , request.getScheme() +"://" + request.getServerName()
                        + ":" +request.getServerPort()
                        + "/download/"
                        + fileName);
            }else{
                retMsg.put("msg" , "没有人员信息");
                retMsg.put("code" , 1);
                return retMsg;
            }

            retMsg.put("code" , 0);
        }catch (Exception e){
            e.printStackTrace();
            retMsg.put("code" , -1);
        }
        return retMsg;
    }

}
